Repository navigation
feat(lk): lk analytics logs, log-patterns and insights under --user-auth - #1146
Merged
Merged
Conversation
Picks up the Public API's project-level observability reads: ListProjectLogs, ListLogPatterns and GetAgentInsights. Nothing calls them yet. Also picks up what the spec gained since the last regeneration: the eval and session label RPCs, GetSessionEvals, ListEvalSessions, GetEvalResults, GetSessionLabelResults, and Agent Builder, whose service is now AgentBuilderService in place of BuilderAgentService. Nothing in lk calls them. Generated from livekit/public-api-server@16e4400
Reads the Public API's ListProjectLogs: the log records that the logs page on the dashboard lists, from the project's agents, client SDKs and LiveKit, newest first, one line per record with its time, level, source, session, logger and message. --json prints the records as the API sends them. --since, or --start and --end (a UTC date or an RFC 3339 time), set the range; without them the server reads the last 24 hours. --log-level, --source, --session-id and --query filter, --sort-order orders, and --limit and the hidden --cursor page, as for lk analytics session logs. The read is for project admins. A refusal says so, a query the server can't parse gets a hint about the search syntax (an attribute needs its @), and with user data recording off the error names the settings page, as the session reads do.
Reads the Public API's ListLogPatterns: the patterns that the logs page on the dashboard groups a project's log records into, ranked, one row each with its number of records, level, source, first and last record, and template. A note on stderr says how many records the range holds and, on a project with many records, that the counts are estimates. --json prints the API's response, with each pattern's counts over time and its variants. It takes the same range flags as lk analytics logs, plus --min-level (the server's default is WARN), --source agent|client, --agent-name, --agent-id, --session-id, --query, --rank events|first-seen|last-seen and --limit. The list is one page, so there is no --cursor. The read is for project admins, and its errors say so as the logs' do.
Reads the Public API's GetAgentInsights: the data that the agent dashboards of LiveKit Cloud show, as four tables. The totals; the latencies that have measurements (end-to-end, LLM and realtime time to first token, TTS time to first byte, transcription and end-of-utterance delay, tool calls) with p50, p95, p99, mean and max; one row for each agent and deployment, busiest first; and one row for each model, with its tokens, characters or seconds of audio. --json prints the API's response. It takes the same range flags as lk analytics logs, reading the last 7 days by default, and --agent-id and --agent-name, repeatable, to select agents. Every project member can read it, so a refusal says the caller has no access to the project rather than that it needs an admin.
- A project read's refusal now goes through readAPIError, which sessionAPIError also calls, so the two no longer repeat the same permission-denied wording. - The help says that a lone --end moves the range too: each read covers its default length before --end. It also says that times print in local time. - The hint for a query the server can't parse no longer says that a missing @ is the only cause. - logs' usage line lists --sort-order and --limit, and --source's help gives a participant joining as its platform example, the proto's own example. - log-patterns prints "1 pattern shown", not "1 patterns". - insights prints a dash for an STT's requests, which the API always counts as 0.
This was referenced Dec 1, 2026
Production now runs v2026-12-01-0249. The spec gained the egress request types of a newer livekit/protocol (StartEgressRequest, its outputs, sources and storage, and a participant kind), the observability token grant clientWrite, and doc text for RemoveMember and a function call's extra metadata. No operation changed, and nothing in lk reads the new types. Generated from livekit/public-api-server@7444be5
… old One read of a project's logs or log patterns covers at most the 7 days before the end of its range, and the server reads a longer range from that point without an error. The empty-read hints sent people to --since for older records, and the logs hint named the 14-day retention beside it, so `--since 14d` quietly read 7 days. The hints now say that --since reads up to 7 days back and --end reaches older records. A read whose range starts more than 7 days before its end also says on stderr that only those 7 days were read, in the form of session list's "Only the last 14 days were searched" hint. A cursor read keeps the range of its first page, so it prints no note.
…es it InvalidLogQuery matched the Public API's whole message, so a reworded refusal would have dropped lk's hint about the search syntax and no test would have failed. The refusal carries no detail to match, so it now matches a 400 whose message names the log search syntax, as lk classifies the API's other errors by HTTP status. The comment names where the API writes the message. Tests check that rewordings that still name the syntax are recognized, including through lk analytics logs, and that the API's other 400s for these reads are not.
The command tests called the fetch functions and option readers directly, so nothing ran a project read end to end. The new script, like session-reads-quiet and key-list-pages, runs logs, log-patterns and insights against the fake Public API, signed in from a CLI config. Each fake answer matches only its exact query, so the script checks that the alias resolves to the project in the path, that the session token is the bearer, and that urfave's parsing of repeated --source, --agent-id and --agent-name, --start/--end, --query and the rest sends the params the API expects. It also checks that --quiet keeps the patterns' count off stderr. The fake now checks the three routes' bodies against the generated types.
The server reads a log patterns limit over 200 as 200, so `--limit 500` printed 200 patterns without a word. Like an explicit --timeout over the Public API's 75s under `lk sip participant create --wait`, a limit over the cap now fails before any request, and the help gives the range the way `lk docs search --limit` does: "Print at most N patterns (1-200, default 50)", which also replaces the `int` placeholder in the help. The logs description said "newest first" even with --sort-order asc. It now says the order follows --sort-order.
Topherhindman
marked this pull request as ready for review
December 1, 2026 20:04
rektdeckard
approved these changes
Dec 1, 2026
Comment on lines
+93
to
+114
| func timeRangeFlags(defaultWindow string) []cli.Flag { | ||
| return []cli.Flag{ | ||
| &cli.StringFlag{ | ||
| Name: "since", | ||
| Usage: "Read the last `DURATION`, such as 15m, 6h, 2d or 1w (default " + defaultWindow + "); can't be used with --start or --end", | ||
| }, | ||
| &cli.StringFlag{ | ||
| Name: "start", | ||
| Usage: "Read from `TIME`: a UTC date (YYYY-MM-DD) or an RFC 3339 time, such as 2026-01-02T15:04:05Z", | ||
| }, | ||
| &cli.StringFlag{ | ||
| Name: "end", | ||
| Usage: "Read up to `TIME`, a date or time as for --start (default now)", | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // timeRangeOptions reads --since, --start and --end. --since starts the range | ||
| // that long before now; --start and --end bound it. Whatever they leave unset | ||
| // the server fills in: the end is now, and the start the read's default length | ||
| // before the end. | ||
| func timeRangeOptions(cmd *cli.Command) (public.TimeRange, error) { |
Member
There was a problem hiding this comment.
Nit: There seems to be a fair amount of overlap with these and the existing utilities in analytics.go(analyticsWindow, parseLookback, validateAnalyticsDateRange). What can we share here? Analytics ranges seem to only support UTC from the CLI side, but is that an actual limitation of the query interface? I think not, and that we may be able to support RFC3339 there too.
The project reads sent only the start for --since, so the server measured the range up to its own now, later than lk's by the request's latency. `lk analytics insights --since 30d` was therefore always a little over the server's 30-day cap and refused. On logs and log-patterns, `--since 7d` measured a little over 7 days against a second read of the clock, and printed the note that only 7 days were read. One helper now reads --since for the project reads and session list: it refuses --start or --end beside it, parses the duration, and reads the clock once, returning the start and that now. The project reads send both ends, so the range is exactly the duration whatever the server's clock says. Session list keeps its end unset: the API-key endpoint reads an end as an exclusive date, so an end of now would leave out today's sessions.
…-user-auth The Public API's session list takes timestamps, but lk sent it only the dates that the API-key endpoint reads. It also sent no end with --since, so the API measured the window up to its own now, and `--since 60d` was always a little over its 60-day cap and refused. Under --user-auth, --start and --end now take an RFC 3339 time as well as a date, parsed as the project reads parse theirs. A window from --since or the default sends its end, now, from the same read of the clock as its start. Without --user-auth nothing changes for a date. A time is refused with "a time in --start is only supported with --user-auth; without it, use a date (YYYY-MM-DD)", in the form of the auth-mode checks' "--X is only supported with --user-auth". The help for --start and --end says which takes what.
urfave/cli splits a slice flag's value at commas, so `--agent-name 'Sales,East'` asked for the agents "Sales" and "East". Nothing refuses a comma in an agent name, so the read answered for the wrong agents, or for none, without an error. The insights command sets DisableSliceFlagSeparator, as the lk agent commands do, so each --agent-name and --agent-id value is taken whole; the help already says to repeat them. The script test sends a name with a comma and matches the exact query.
A room's tags are free text: they come from CreateRoomRequest.tags or a token's RoomConfiguration.tags, and nothing on the way to the analytics store refuses a comma. urfave/cli split each --tag value at commas, so `--tag 'team,support'` filtered on two tags that match nothing, without an error. Session list sets DisableSliceFlagSeparator, as the lk agent commands and insights do, so each --tag value is taken whole; the help already says to repeat the flag. It applies to --status too, which is repeatable the same way. A script test sends a tag with a comma and matches the exact query.
pageOptions and the log patterns options narrowed --limit to an int32 before they checked it, so a large limit wrapped: `--limit 4294967346` became 50 and was accepted, and `--limit 2147483648` became negative and was refused as "limit must not be negative". 396a599's "at most 200" check for log-patterns ran after the wrap. Both now check the int first, beside their existing "greater than 0" check: log-patterns refuses a limit over 200, and pageOptions, which logs and the session reads share, one over the int32 maximum, both as "limit must be at most N".
…pping Several commands narrowed an int flag with int32(cmd.Int(...)), so a large value wrapped to another one: session list sent `--limit 2147483648` as a negative page size, and 4294967346 as 50. The same narrowing was in user list, workspace list and its project list, number search and number list (--limit and --offset, with and without --user-auth), and simulate's --num-simulations, --concurrency and --samples. int32Flag reads such a flag and refuses a value outside an int32 with "limit must be at most 2147483647", as pageOptions now does for the session reads. Each command reads it before the request that sends it.
rektdeckard
approved these changes
Dec 1, 2026
This reverts commit bd6c6b9. urfave/cli turns comma splitting off only for a whole command, so the change also stopped `session list --status active,closed` from splitting. lk treats a comma as the list separator in every repeatable flag, so a tag with a comma isn't supported, as elsewhere in lk.
This reverts commit 6b9d9af. urfave/cli turns comma splitting off only for a whole command, so the change also stopped `insights --agent-id CA_1,CA_2` from splitting. lk treats a comma as the list separator in every repeatable flag, so an agent name with a comma isn't supported, as elsewhere in lk.
…eal commands The tests of the flag readers ran them on a command of their own, so nothing ran the real session list and insights commands with a comma in a repeatable flag, and a change to how those commands split values went unseen. Script tests now run `session list --status active,closed --tag team,beta` and `insights --agent-id CA_1,CA_2`, and the same flags repeated, against fake answers that match only the split query. They fail with DisableSliceFlagSeparator set on either command.
There was a problem hiding this comment.
Devin Review found 1 new potential issue.
3 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
Topherhindman
added a commit
that referenced
this pull request
Dec 2, 2026
int32(cmd.Int("limit")) wrapped a --limit over 2147483647 to another
page size, such as 4294967346 to 50. Both commands now read it with
int32Flag, as the other list commands do since #1146, and refuse it
before any request.
Topherhindman
added a commit
that referenced
this pull request
Dec 2, 2026
int32(cmd.Int("limit")) wrapped a --limit over 2147483647 to another
page size, such as 4294967346 to 50. Both commands now read it with
int32Flag, as the other list commands do since #1146, and refuse it
before any request.
Topherhindman
added a commit
that referenced
this pull request
Dec 3, 2026
…auth (#1136) * feat(public): builder agent methods on the Public API client Wraps the Public API's AgentBuilderService: list, get, create, update, deploy, delete, list versions, and the code URL. Configurations travel as raw JSON in both directions. The generated configuration type drops properties that this client's spec predates, so a configuration read through it and written back would lose them; reads decode the response body with the config kept verbatim, and writes send the caller's JSON through the WithBody variants. HasHiddenHeaderValues finds the ******** that a caller without agent:manage reads in place of each header value. * feat(lk): lk agent builder manages builder agents under --user-auth Adds `lk agent builder` with list, get, create, update, deploy, delete and versions, on the Public API's AgentBuilderService. Builder agents exist only on LiveKit Cloud, so the commands require --user-auth and call pkg/public directly, with no API-key backend. Like the other Public-API-only groups, the group is hidden until a user signs in. - Configurations are JSON files (--config-file FILE, or - for stdin), sent as written. A file that holds a whole builder agent is refused: the API ignores unknown properties, so it would reset the configuration to its defaults. - get --json and versions --json print each configuration verbatim, and warn when header values show as ********, which create and update refuse. - deploy --wait reads the agent every 3 seconds until the new deployment runs or fails, for up to 15 minutes. A status read before the new deployment shows can be the previous one's, so RUNNING counts only after BUILDING or STARTING, or with a deployedAt after the deploy, and a failure only after BUILDING or STARTING. - Lists print one page, with the command that reads the next. The list table has no deployed version column: ListAgents doesn't set deployment.versionId, only GetAgent does. * refactor(public): name the recording download client for every signed URL The builder agent code download needs the same client: no credentials, no cookie jar, and timeouts. recordingClient becomes signedURLClient. No behavior change. * feat(lk): lk agent builder download fetches a version's agent code download asks GetBuilderAgentCodeURL for a signed URL, valid for 60 seconds because lk uses it at once, then fetches the zip through the signed-URL client, without the session token. It writes the zip to --output, or to the name the server suggests, which must not exist yet; --unzip DIR unpacks it into an empty or new directory instead. The code holds every header value of the configuration in plaintext, so lk writes files 0600 and directories 0700. Unpacking goes through os.Root, so no entry lands outside DIR, and an entry that is neither a file nor a directory is an error. As with recordings, no error prints the URL's signature. * fix(lk): a refused builder command doesn't point at an API-key path cloudAPIError answers a permission denial with "re-run without `--user-auth`". Builder agents have no API-key path, so that advice only leads to "only available under --user-auth". cloudOnlyAPIError says the account lacks access and stops there; every other error reads as cloudAPIError. The builder commands use it. * fix(lk): webhook, user and workspace refusals don't point at an API-key path These groups have no API-key implementation either, so they answer through cloudOnlyAPIError too. Each change replaces one call. * fix(lk): builder --config-file reports where its JSON is broken A config file with a syntax error, such as a trailing comma, was reported as "the configuration must be a JSON object", which hides the real problem. A syntax error now prints its line, column and the parser's message; valid JSON that isn't an object keeps the old message. The line and column come from lineAndColumn, which the eval commands added for their --file. * fix(lk): deploy --wait ends on SLEEPING and checks freshness by server time - A deployment whose agent scales to zero before the wait reads it settles in SLEEPING, which never ended the wait: it ran 15 minutes and failed. A sleeping agent is deployed, and a dispatch starts it, so SLEEPING now ends the wait as RUNNING does, after the same freshness check, and lk says the agent sleeps until a dispatch. - An up status without a BUILDING or STARTING before it counted as the new deployment when its deployedAt was after the local time of the deploy. A client clock behind the server's could take the previous deployment for the new one. The reference is now the deploy response's Date header plus a second, since the header is truncated to the second: both times are server times. Without a Date header, only a BUILDING or STARTING lets the wait end. DeployBuilderAgent returns the Date beside the API's answer, which --json prints unchanged. * fix(lk): deploy --wait says the deployment continues however it stops - Ctrl-C said "stopped waiting after 15m0s", as the timeout does. A cancel now says "stopped waiting", and only the timeout names its duration. - One failed status read ended the wait, without saying that the deployment goes on. A network error, a 429 or a 5xx is now retried up to 3 times in a row, waiting twice as long before each try. - Every early end, whether a cancel, the timeout or an error that stops the wait, ends with how to follow the deployment: lk agent builder get ID. * fix(lk): download --output makes an existing file private too OpenFile applies its mode only to a file it creates, so a zip written over an existing 0644 file stayed 0644, though the agent code holds header values in plaintext. writePrivateFile now sets 0600 on the open file before it writes, for a new and a replaced file alike. * fix(lk): a failed --unzip leaves its directory as it found it An entry that failed partway through an unpack left the files before it in DIR, so a second try was refused because DIR wasn't empty. On an error, lk now removes DIR when the unpack created it, and otherwise empties it again, since --unzip only takes an empty directory. * test(lk): show that a config property lk doesn't know reaches the API The script tests sent a config with an unknown property, but the fake logged no bodies, so nothing showed it reached the wire. The fake now keeps each request's body, and `body METHOD URL` prints the last one. agent-builder-with-user-auth.txtar checks that stateTools, which the generated types don't have, is in the create and the update body. * feat(lk): lk agent builder names Agent Builder agents as the API does livekit/public-api-server#220 calls the AgentBuilderService resource an "Agent Builder agent", and names its cloud agent ID (CA_) `cloudAgentId`. lk's names and output follow it. The routes and the generated client are unchanged. - pkg/public: builder_agents.go is agent_builder.go. Its types and methods say AgentBuilderAgent. - pkg/public/render: the tables' Agent ID column is Cloud Agent ID. - cmd/lk: the argument is AGENT_ID, and the group's help says it is the AB_ ID, not the CA_ ID other lk agent commands take. Messages say "Agent Builder agent". delete --json prints {"agentId": ..., "deleted": true}. * fix(lk): a failed --unzip removes only what it made download checks that the --unzip directory is empty before it fetches the zip, which takes a while. Anything written to the directory in that time was deleted when the unpack then failed: the cleanup emptied the whole directory. An unpack that collided with such a file failed and deleted it too. The unpack now records each file and directory it makes, and its undo removes those alone, newest first, each a directory only while empty. Parents of the directory that it made go the same way. Entry paths that aren't local are refused before os.Root sees them. * fix(lk): deploy --wait reports a failure whose build it never saw A failure ended the wait only after a BUILDING or STARTING read, so a deployment that failed while status reads were failing, or before the first read, ran to the 15-minute timeout and was reported as one. deploy --wait now reads the agent before it deploys. When that read doesn't show a failure, a failure read later is this deployment's, and ends the wait as one. When the agent had already failed, or couldn't be read, a failure without a BUILDING or STARTING may still be the old one: the API has no deployment ID or build time that tells them apart, so the wait still needs to see the build start. * fix(lk): --config-file names a missing file in lk's own words A missing config file printed the OS error, "open missing.json: no such file or directory" on macOS and Linux and "The system cannot find the file specified." on Windows, so agent-builder-refusals.txtar failed on Windows. lk now says "--config-file missing.json: the file doesn't exist", like its other --config-file errors, and prefixes any other read error with the flag and path. * fix(lk): deploy --wait treats an unknown status before the deploy as a failure The API leaves an agent's deployment out when it can't read the status. deploy --wait took that baseline as "not failed", so a failure read after the deploy, which could still be the previous deployment's, ended the wait as this deployment's failure. An unknown status, like an unreadable agent, now counts as possibly failed, so such a failure ends the wait only after a BUILDING or STARTING. * fix(lk): agent builder list and versions refuse a --limit that wraps int32(cmd.Int("limit")) wrapped a --limit over 2147483647 to another page size, such as 4294967346 to 50. Both commands now read it with int32Flag, as the other list commands do since #1146, and refuse it before any request. * fix(lk): agent builder usage lines leave out --project and --user-auth #1156 resolves a user-auth command's project from --subdomain, LIVEKIT_URL and livekit.toml as well as --project, and makes user auth the default in 3.0. The other Public-API commands' usage lines, such as lk agent eval's, name neither flag; the group's "(requires --user-auth)" stays, as theirs does. * chore(public): regenerate the Public API client Picks up AgentBuilderService.UpdateAgentSecrets, which livekit/public-api-server#242 added. It also drops the eval criterion type "code" and its `check` field (livekit/public-api-server#256), which lk doesn't use. No hand-written code changes. Generated from livekit/public-api-server@372fb27, which is production (v2026-12-02-2258) * feat(lk): lk agent builder update-secrets sets and removes an agent's secrets Wraps AgentBuilderService.UpdateAgentSecrets, which livekit/public-api-server#242 added. The secrets that the command doesn't name keep their values. The update makes no version and doesn't deploy, but the agent restarts to read them. The API asks agent_secret:manage. - Secrets come as lk agent update-secrets takes them: --secrets KEY=VALUE, repeatable and taken whole when the value has a comma, and --secrets-file. lk drops the LIVEKIT_ names, which LiveKit Cloud sets. There is no --secret-mount: an Agent Builder agent reads only environment secrets, and the API refuses a file secret. - --remove NAME removes a secret. There is no --overwrite: the API only sets and removes. - lk sends the secrets sorted by name, and refuses a run with nothing to set or remove before any request. * fix(lk): a KEY=VALUE flag that lk can't parse doesn't print its value parseKeyValuePairs reads --secrets for lk agent create, deploy, update, update-secrets and lk agent builder update-secrets, and --attribute for lk agent create and deploy, lk room, lk token and lk perf. It put the whole pair in its error, and godotenv's error, which quotes the pair again. For --secrets that printed the secret. The error now names the flag, the pair's position and its key, which is the text before the first =. * fix(lk): a $ in a --secrets or --attribute value reaches the API as written parseKeyValuePairs parses each KEY=VALUE pair with godotenv, which expands $NAME and ${NAME} from the variables parsed before them. A pair has none, so the expansion could only erase: --secrets 'DB_PASSWORD=rotated$SUFFIX' stored "rotated". Each pair is now parsed with its unescaped $ signs hidden. Quotes, an escaped \$, comments and export still read as before, and --secrets-file, a real dotenv file, still expands. agent-builder-update-secrets.txtar checks that the API gets the value whole, and that a pair lk can't parse names its key but not its value. * fix(lk): agent builder deploy --json prints one shape with or without --wait deploy --json printed the deploy's answer, {"versionId", "status"}, but deploy --wait --json printed the whole agent, so a script had to know which flags it ran with. Both now print the deploy's answer. After --wait its status is the one the wait ended on, RUNNING or SLEEPING, as lk sip's --wait keeps the answer's shape. Without --json, --wait still prints the agent's table. * fix(lk): agent builder download --unzip stops at 256 MiB unpacked The download reads at most 100 MiB of zip, but a zip can unpack to far more than its size, and --unzip copied each entry without a bound. It now copies through a LimitReader, and stops when the files together pass maxUnpackedAgentCode (256 MiB). The error says so, and the unpack removes what it wrote, as on any other error. * fix(lk): agent builder deploy --wait stops when the agent is deleted A wait read DELETING, NOT_DEPLOYED and UNSPECIFIED as "not up yet", so deleting the agent during deploy --wait polled for 15 minutes and ended on the timeout, and a deleted agent's 404 ended it with "the deployment continues". Now: - DELETING ends the wait: the agent is being deleted. - NOT_DEPLOYED ends it after a BUILDING or STARTING: the deployment went away. Before the build shows, it can be the state before the build, so the wait goes on. - A 404 ends it without the "deployment continues" hint: the deploy found the agent, so it was deleted since. - UNSPECIFIED, or a status lk doesn't know, keeps the wait going: it may pass, and the timeout bounds it. * fix(lk): a KEY=VALUE flag keeps bytes that aren't UTF-8 2ceaa2c hid each $ by ranging over the pair as runes and writing each rune back, which turned a byte that isn't UTF-8 into U+FFFD, so a quoted --secrets value with a $ and such a byte reached the API changed. godotenv does the same to an unquoted value on its own, with or without a $, as it reads one as runes. hideFromDotenv now walks the pair by byte, and hides a byte that isn't UTF-8 behind a private-use rune too, as it hides a $. The runes are ones the pair doesn't hold, and restore turns each back into its byte. A test covers single-quoted, double-quoted and unquoted values with a $ and such bytes, and valid UTF-8, U+FFFD and private-use runes, which pass unchanged. * fix(lk): key, member and invite refusals don't point at an API-key path lk project key, member and invite run only under --user-auth, as webhooks, users and workspaces do, but a refusal for the user's role still told them to re-run without --user-auth, where the commands don't exist. They use cloudOnlyAPIError now, as dee252f's groups do.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds three
lk analyticscommands for the project-level observability reads that the Public API serves in production. They read a whole project over a time range, where the existinglk analytics session …commands read one session.Why
The Public API serves a project's logs (livekit/public-api-server#181), log patterns (livekit/public-api-server#182) and agent insights (livekit/public-api-server#183) in production, and the MCP has them as tools. lk had no command for them. A person or a coding agent signed in with
--user-authcouldn't search a project's logs, see what errors repeat, or read agent latencies without the dashboard.Commands
lk analytics logsGET /v0/projects/{id}/logs(ListProjectLogs)lk analytics log-patternsGET /v0/projects/{id}/log-patterns(ListLogPatterns)lk analytics insightsGET /v0/projects/{id}/agent-insights(GetAgentInsights)All three take
--since DURATION, or--start/--end(a UTC date or an RFC 3339 time). They send no range when none is given, so the server's defaults apply. They also take--json, which prints the API's response.--log-level(repeatable),--source agent|client|platform(repeatable),--session-id,--query,--sort-order(default desc), and--limit/ hidden--cursor, which page likelk analytics session logs.--min-level(server default warn),--source agent|client,--agent-name,--agent-id,--session-id,--query,--rank events|first-seen|last-seen,--limit(server default 50, max 200). The list is one page, so there is no cursor.--agent-idand--agent-name, both repeatable.Errors:
logsorlog-patternsgets the server's 403 plus "requires being a project admin".@(@lk.cloud_agent_id:CA_…).analyticsgroup, refuse without--user-auth, and check their flags before the project lookup, all like the session reads.What changed
chore(public): regeneratespkg/public/oapifrom livekit/public-api-server@16e44007, the commit that production ran on 2026-11-23 (v2026-11-23-2321). Its spec is the same asv2026-11-23-1735's. The regenerated client also adds the eval, session label and Agent Builder operations.BuilderAgentServicebecomesAgentBuilderService. Nothing in lk calls either.pkg/public:ListProjectLogs,ListLogPatternsandGetAgentInsights, with option structs that are checked before a request is sent. AlsoTimeRangeand theInvalidLogQueryclassifier.pkg/public/render: the logs lines and the patterns and insights tables.cmd/lk/analytics_project.go: the three commands and the shared range flags.observabilityDisabledErrornow takes a subject, so a project read can use it too.chore(public): regeneratespkg/public/oapiagain, from livekit/public-api-server@7444be53, the commit that production runs now (v2026-12-01-0249). The spec gained the egress request types of a newer livekit/protocol, theclientWritetoken grant, and doc text. No operation changed.fix(lk): the empty-read hints oflogsandlog-patternspoint at--endfor records older than 7 days, since one read covers at most the 7 days before its end. A range longer than that says on stderr that only those 7 days were read.fix(public):InvalidLogQuerymatches a 400 whose message names the log search syntax, not the whole message, so a reworded refusal keeps the hint.test(lk): a script test runs the three commands signed in against the fake Public API. It checks the project lookup, the bearer, the project in the path, and the query that each flag sends.fix(lk): alog-patterns --limitover 200 fails before any request instead of being clamped, and thelogsdescription says that the order follows--sort-order.fix(lk):--sincesends both ends of the range from one read of the clock, soinsights --since 30dis exactly 30 days and the server no longer refuses it, andlogs/log-patterns --since 7dno longer print the 7-day note. One helper reads--sincefor the project reads and session list.feat(lk): under--user-auth,session list --start/--endalso take an RFC 3339 time, and--sinceor the default window sends its end, so--since 60dfits the API's 60-day cap. Without--user-auth, dates work as before and a time is refused.fix(lk):--limitis checked before it narrows to an int32, so a large value is refused instead of wrapping (4294967346was read as 50), forlogs,log-patternsand the session reads.fix(lk): the same check for the other int flags that a request holds as an int32: session list, user list, workspace list and its project list, number search and list, and simulate's--num-simulations,--concurrencyand--samples.--statusand--agent-idfrom splitting; lk keeps a comma as the list separator in every repeatable flag.One PR, not three: the commands share the regeneration, the range flags, the project-read action and the error handling. Each endpoint is its own commit.
Since review, the PR also touches commands outside the new three:
session list(RFC 3339 and an explicit end under--user-auth) and the int32 limit check in the user, workspace, number and simulate commands (items 11 and 15).Overlaps with open PRs
oapi.gen.gofrom other public-api-server commits. A test merge of each shows a conflict inoapi.gen.goonly. Whichever PR merges second regenerates.--agent-idtosession list, and these commands use the same flag name.Testing
go build ./...,go vet ./...andgo test ./...pass.go test -raceoncmd/lkandpkg/public/...passes.golangci-lint run ./cmd/lk/... ./pkg/public/...reports 0 issues (local v2.14.0; CI pins v2.11.4).api.staging.livekit.cloud), read-only, with an admin user and the+writeand+readtest users on projectp_3nkg2glzm65:lk analytics logsandlog-patternsrefuse the WRITE and READ members with 403.insights.@gets the hint.Demo
Recorded on staging with this branch at 1a05d61. All the commands only read. The MP4 can be found in slack.
logs --log-level error, as an adminlogs --query '@lk.cloud_agent_id:CA_… participant'@: a 400 with the hintlog-patterns, WARN and up by defaultlog-patterns --min-level info --rank last-seen --limit 4insightslogs(403)log-patterns(403)insights